/*
 *  http.h
 *
 *  Very simple HTTP file get.  Supports chunked encoding and SSL.
 *
 * Copyright (c) 2006 Karlan Thomas Mitchell<karlanmitchell@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, is prohibited except by
 * Karlan Thomas Mitchell.
 *
 * THIS SOFTWARE IS PROVIDED BY KARLAN THOMAS MITCHELL AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */






#ifndef __SIMPLE___WGET__H__
#define __SIMPLE___WGET__H__
#include "mini_db.h"
#include "portable_socket.h"
#include <errno.h>
#include <stdio.h>

#ifndef PATH_MAX
#define PATH_MAX 255
#endif

struct st_wget_gui {
       int * is_chunked;
       off_t * total_size;
       off_t * bytes_downloaded;
       };

int wget_file(char * remote_http_location, char * local_file, struct st_wget_gui * gui_data);
int wget_file_bare(int is_ssl, char * ip, int short unsigned port, char * host, char * remote_file, char * local_file, struct st_wget_gui * gui_data);
off_t sock_to_file(FILE * filed, struct st_psocket * socket_data, off_t len);
off_t sock_to_file_gui(FILE * filed, struct st_psocket * socket_data, off_t len, struct st_wget_gui * gui_data);
int http_read_file(struct st_psocket * socket_data, char * local_file, struct st_mdb * protocol_message, struct st_wget_gui * gui_data);
int http_send_message(struct st_psocket * socket_data, struct st_mdb * protocol_message);
int http_read_message(struct st_psocket * socket_data, struct st_mdb * protocol_message);
#endif 
